<template>
	<view>
		<!-- 主盒子 -->
		<view class="box">
			<!-- 用户信息 -->
			<view class="userInfo">
				<!-- 头像 -->
					<view class="header">
						<image :src="node.userHeader"></image>
					</view>
				<!-- 配置信息 -->
				<view class="info">
					<!-- 名称 -->
					<view>
						<text>{{node.userName}}</text>
					</view>
					<!-- 帖子信息 -->
					<view>
						<text style="font-size: 10px;color: #808080;">
							发布时间:{{node.nodeTime}} 🔥:{{node.nodeLook}}
						</text>
					</view>
				</view>
			</view>
			<!-- 内容 -->
			<view class="context">
				<text style="font-size: 14px;">{{node.nodeMess==null?'':node.nodeMess}}</text>
			</view>
			<!-- 图片 -->
			<view class="image" >
				 <navigator :url="'/pages/details/details?id='+node.nodeId">
						<image v-for="item in node.arrImgs" :src="item"></image>
				</navigator>
			</view>
			<!-- 功能 -->
			<view class="method">
				<button class="icon iconfont" :data-id="node.nodeId" open-type="share" style="background: #F0AD4E;height: 100%;margin-right: 10px;" size="mini">&#xe739;</button>
				<button class="icon iconfont" @click="collent" v-if="is==false"  style="background: #F0AD4E;height: 100%;margin-right: 10px;" size="mini">&#xe627;</button>
				<button class="icon iconfont" v-if="is" @click="delCollent"  style="background: #F0AD4E;height: 100%;margin-right: 10px;" size="mini">&#xe684;</button>
				<button class="icon iconfont" @click="del"  style="background: #F0AD4E;height: 100%;" size="mini" v-if="del">del</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"Node",
		props:["del","node","iscollent"],
		data() {
			return {
				FriendInfo:{
					openid:null,
					avatarUrl:"https://thirdqq.qlogo.cn/qqapp/1112182184/2D838C6B7E2FC02E97BF7EFA87A40CFD/100",
					nickname:"A.头像库"
				},
				collentFlag:-1,
				is:this.iscollent
			}
		},
	
	
	
		methods: {
			del(){
				var that = this
				var token = null
				uni.getStorage({
					key:"token",
					success(da) {
						token=da.data
					}
				})
				uni.showModal({
					title:"删除",
					content:"删除将无法恢复",
					
					success(res) {
						if(res.confirm){
							uni.request({
								url:"https://app.waghost.com/api/node/delNode/"+that.node.nodeId,
								header:{
									"Authorization":"TOKEN "+token
								},
								method:"DELETE",
								success(va) {
									uni.showToast({
										title:va.data.message
									})
									uni.navigateTo({
										url:"../../pages/myNodes/myNodes"
									})
								}
							})
						}
					}
				})
			},
			delCollent(){
				var that = this
				uni.getStorage({
					key:"token",
					success(va) {
						that.collentFlag=-1
						uni.request({
							url:"https://app.waghost.com/api/collent/collentnode/"+that.node.nodeId+"/"+that.collentFlag,
							header:{
								"Authorization":"TOKEN "+va.data
							},
							method:"PUT",
							success(va) {
								uni.showToast({
									title:"取消成功"
								})
								that.is=false
							},
							
						})
					},
					fail() {
						uni.showModal({
							content:"请进行登录在操作"
						})
					}
				})
			
			},
			collent(){
				var that = this
				uni.getStorage({
					key:"token",
					success(va) {
						that.collentFlag=1
						uni.request({
							url:"https://app.waghost.com/api/collent/collentnode/"+that.node.nodeId+"/"+that.collentFlag,
							header:{
								"Authorization":"TOKEN "+va.data
							},
							method:"PUT",
							success(va) {
								if(va.data.code==200){
									uni.showToast({
										title:"收藏成功"
									})
								}
								that.is=true
							},
							
						})
					},
					fail() {
						uni.showModal({
							content:"请进行登录在操作"
						})
					}
				})
			
			}
		}
	}
</script>

<style scoped>
	
	.box{
		width: 100%;
		height: auto;
		box-shadow: 0 0 12px rgba(0, 0, 0, 0.1);
		padding: 10px 10px 10px 10px;
		box-sizing: border-box;
		margin-top: 15rpx;
		border-radius: 5px;
	}
	.box>.userInfo{
		width: 100%;
		height: 70px;
		display: flex;
	}
	.box>.userInfo>.header{
		width: 70px;
		box-sizing: border-box;
		height: 100%;
		padding: 10px;
	}
	.header>image{
		width: 100%;
		height: 100%;
		border-radius: 50%;
	}
	.box>.userInfo>.info{
		box-sizing: border-box;
		padding-top:15px;
		width: 70%;
		height: 100%;
	}
	.info{
		font-size: 15px;
	}
	.context{
		
	}
	.image{
		margin-top: 10px;
	}
	.image image{
		width: 200rpx;
		height: 200rpx;
		margin-right: 10px;
	}
	.method{
		width: 100%;
		margin-top: 10px;
		height: 30px;
		text-align: right;
	}
</style>
